;solution to euler 10

;slow

;adapted from euler 7. alogirthm as of 4/7/2008
(defun isprime (n lowerprimes)
	(loop for prime in lowerprimes do
		(when (> (* prime prime) n) (return-from isprime t))
		(if (= (mod n prime) 0)
			(return-from isprime nil)))
	(return-from isprime t))


(defun prime-gen (maxn)
	(let ((primes (list 2)) (i 1))
		(loop
			(when (> i maxn) (return))
			(setf i (+ i 2))
			(when (isprime i primes)
				;(when (= (mod count 100) 0) (print count))
				(setf (cdr (last primes)) (cons i nil))))
				;(setf primes (append primes (list i)))))
		(return-from prime-gen primes)))
		
(defun solve-euler10 ()
	(let ((primes (prime-gen 2000000)) (sum 0))
		(dolist (prime primes)
			(setf sum (+ sum prime)))
		(format t "Euler 10: ~a" sum)))
		
